package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.CustomerDao;
import com.atguigu.jxc.dao.SaleListDao;
import com.atguigu.jxc.dao.UserDao;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.entity.SaleList;
import com.atguigu.jxc.entity.User;
import com.atguigu.jxc.service.SaleListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author qingyu
 * @create 2022-01-02 21:45
 * @description
 */
@Service
public class SaleListServiceImpl implements SaleListService {

    @Autowired
    private SaleListDao saleListDao;
    @Autowired
    private UserDao userDao;
    @Autowired
    private CustomerDao customerDao;

    /**
     * 销售单查询（可查询条件：销售单号、客户、付款状态）
     * @param saleNumber
     * @param customerId
     * @param state
     * @param sTime
     * @param eTime
     * @return
     */
    @Override
    public List<SaleList> list(String saleNumber, Integer customerId, Integer state, String sTime, String eTime) {
        List<SaleList> saleLists = saleListDao.list(saleNumber,customerId,state);
        saleLists.forEach(saleList -> {
            Integer userId = saleList.getUserId();
            Integer customerIdDb = saleList.getCustomerId();
            Customer customer = customerDao.getCustomerById(customerIdDb);
            User userByIdDb = userDao.getUserById(userId);
            saleList.setTrueName(userByIdDb.getTrueName());
            saleList.setCustomerName(customer.getCustomerName());
        });
        return saleLists;
    }
}
